package two;
public class Certificate implements Cloneable {
    private String studentName;
    private String schoolName;
    private StudentId studentId; // 引用类型字段（学号）

    public Certificate(String studentName, String schoolName, StudentId studentId) {
        this.studentName = studentName;
        this.schoolName = schoolName;
        this.studentId = studentId;
    }

    // 获取学生姓名
    public String getStudentName() {
        return studentName;
    }

    // 设置学生姓名
    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    // 获取学校名称
    public String getSchoolName() {
        return schoolName;
    }

    // 设置学校名称
    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

    // 获取学号
    public StudentId getStudentId() {
        return studentId;
    }

    // 设置学号
    public void setStudentId(StudentId studentId) {
        this.studentId = studentId;
    }

    // 浅克隆：复制对象，但引用字段仍指向同一内存地址
    @Override
    public Certificate clone() throws CloneNotSupportedException {
        return (Certificate) super.clone(); // 调用Object的clone()方法
    }

    // 深克隆：复制对象并单独克隆引用类型字段
    public Certificate deepClone() throws CloneNotSupportedException {
        Certificate cloned = (Certificate) super.clone();
        // 深克隆: 对引用类型字段（学号）进行单独克隆
        cloned.studentId = new StudentId(this.studentId.getId());
        return cloned;
    }

    // 打印证书信息
    public void printCertificate() {
        System.out.println("学生姓名: " + studentName);
        System.out.println("学校名称: " + schoolName);
        System.out.println(studentId); // 显示学号
    }
}
